﻿using System;
using System.Collections.Generic;
using System.Text;
using Csla.Data;


namespace MinaspetroLibrary.CurriculoPack
{
    [Serializable()]
    public class CursoChildInfo : Csla.ReadOnlyBase<CursoChildInfo>
    {
        #region Business Properties and Methods

        //declare members

        private Guid _id = Guid.NewGuid();

        private Guid _idCurriculo = Guid.NewGuid();

        private String _descricao = String.Empty;
        
        private String _cidade = String.Empty;
       
        private String _cargaHora = String.Empty;
        
        private String _instituicao = String.Empty;
        
        private DateTime _dataInicio = DateTime.MinValue;
        
        private DateTime _dataFim = DateTime.Now;

        [System.ComponentModel.DataObjectField(true, true)]
        public Guid Id
        {
            get
            {
                return _id;
            }
        }


        public Guid IdCurriculo
        {
            get
            {
                return _idCurriculo;
            }
        }

        public String Descricao
        {
            get
            {
                return _descricao;
            }
        }

        public String Cidade
        {
            get
            {
                return _cidade;
            }
        }

        public String CargaHora
        {
            get
            {
                return _cargaHora;
            }
        }

        public String Instituicao
        {
            get
            {
                return _instituicao;
            }
        }

        public DateTime DataInicio
        {
            get
            {
                return _dataInicio;
            }
        }

        public DateTime DataFim
        {
            get
            {
                return _dataFim;
            }
        }


        protected override object GetIdValue()
        {
            return _id.ToString();
        }

        #endregion //Business Properties and Methods

        #region Authorization Rules
        protected override void AddAuthorizationRules()
        {
            //TODO: Define authorization rules in CursoChildInfo

        }

        #endregion //Authorization Rules

        #region Factory Methods
        internal static CursoChildInfo GetCursoChildInfo(SafeDataReader dr)
        {
            return new CursoChildInfo(dr);
        }

        private CursoChildInfo(SafeDataReader dr)
        {
            Fetch(dr);
        }
        #endregion //Factory Methods

        #region Data Access

        #region Data Access - Fetch
        private void Fetch(SafeDataReader dr)
        {
            FetchObject(dr);
            //load child object(s)
            FetchChildren(dr);

        }

        private void FetchObject(SafeDataReader dr)
        {
            _id = new Guid(dr["Id"].ToString());
            _idCurriculo = new Guid(dr["IdCurriculo"].ToString());
            _descricao = dr.GetString("Descricao");
            _cidade = dr.GetString("Cidade");
            _cargaHora = dr.GetString("CargaHora");
            _dataInicio = dr.GetDateTime("DataInicio");
            _instituicao = dr.GetString("Instituicao");
            _dataFim = dr.GetDateTime("DataFim");
        }

        private void FetchChildren(SafeDataReader dr)
        {
        }
        #endregion //Data Access - Fetch
        #endregion //Data Access
    }
}
